package com.ds.common.satoken.config;

import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
import cn.dev33.satoken.stp.StpLogic;
import com.ds.common.factory.YmlPropertySourceFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @class: SaTokenConfigure
 * @description:
 * @author: fs
 * @create: 2024/1/22 13:37
 **/
@Configuration
@RequiredArgsConstructor
@PropertySource(value = "classpath:satoken.yml", factory = YmlPropertySourceFactory.class)
@EnableConfigurationProperties(SecurityProperties.class)
public class SaTokenConfig implements WebMvcConfigurer {

    private final SecurityProperties securityProperties;

    // 注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册 Sa-Token 拦截器，校验规则为 StpUtil.checkLogin() 登录校验。
        //registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
        //        .addPathPatterns("/**")
        //        .excludePathPatterns(securityProperties.getExcludes());
    }

    /**
     * 整合jwt
     *
     * @return
     */
    @Bean
    public StpLogic getStpLogicJwt() {
        return new StpLogicJwtForSimple();
    }
}

